package Method;

import Book.Book;
import Book.BookList;
import java.util.Scanner;

//删除图书
public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList){
        System.out.println("请输入删除图书名称：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();

        for(int i=0;i<bookList.getBooksNum();i++){
            if(bookList.getBook(i).getName().equals(name)){
                int j=0;
                for (j = i; j < bookList.getBooksNum()-1; j++) {
                    bookList.setBook(bookList.getBook(j+1),j);
                }
                bookList.setBooksNum(bookList.getBooksNum()-1);
                bookList.setBook(null,j);
                System.out.println("删除成功！");
                return ;
            }
        }
        System.out.println("删除失败，未找到该图书！");
    }
}
